const path = require("path");
const nodeExternals = require("webpack-node-externals");
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: "./src/main.js", // 你的入口文件
  target: "node", // 指定打包目标为Node.js环境
  output: {
    path: path.resolve(__dirname, "dist"), // 输出目录
    filename: "bundle.js", // 输出文件名
  },
  externals: [nodeExternals({
    allowlist: ['ejs', 'pdf-poppler','multer','express'] // 强制打包这些模块
  })], // 排除node_modules中的模块
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        },
      },
    ],
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        // 复制 views 文件夹到 build/views
        { from: "./src/templates", to: "templates" },
      ],
    }),
  ],
};
